#include "Lexical.h"
#include "Grammatical.h"
#include <fstream>

void readFile(const string& path, string& text) {
    ifstream in(path);
    if (!in) {
        cerr << "Cannot open the File : " << path << endl;
        return;
    }
    string line;
    while (getline(in, line)) {
        text += line + "\n";
    }
    in.close();
}

void writeFile(const string& path, const vector<pair<string, string>>& output) {
    ofstream out(path);
    for (const auto& p : output) {
        out << (p.second.empty() ? "<" + p.first + ">\n" : p.first + " " + p.second + "\n");
    }
}

int main() {
	const string path1 = "testfile3.txt";
	const string path2 = "output3.txt";
	string text;
	readFile(path1, text);

	lexical Lexical;
	grammatical Grammatical;
	Grammatical.bootGrammatical();

	auto words = Lexical.wordDivision(text);
	auto output = Grammatical.resolve(words);

	writeFile(path2, output);
}